package com.brilliance.project.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.brilliance.project.common.Constants;
import com.brilliance.project.common.tools.StringUtil;
import com.brilliance.project.dao.IBrt_sDao;
import com.brilliance.project.webapp.form.BRT_SForm;

@Component("brt_sDaoImpl")
public class Brt_sDaoImpl extends BaseDaoImpl implements IBrt_sDao {

	@Override
	public List<BRT_SForm> query(BRT_SForm brt_sForm) {
		// 查总笔数
		Integer totleCount = (Integer) this.getSqlSession().selectOne(
				"brt_s.countQuery", brt_sForm);
		setPageInfo(totleCount, brt_sForm);
		Map map = new HashMap();
		StringBuffer sb = new StringBuffer();
		StringBuffer sb1 = new StringBuffer();
		sb.append("select BRTPRO_COD, BRTBR, BRTBRNAM, BRTGACBR, BRTLQDLEV, BRTLQDBR, BRTLACSEQ from dbo.BRT_S ");
		if (!StringUtil.isNull(brt_sForm.getBrtpro_cod())) {
			sb1.append(" and BRTPRO_COD = '").append(brt_sForm.getBrtpro_cod())
					.append("' ");
		}
		if (!StringUtil.isNull(brt_sForm.getBrtbr())) {
			sb1.append(" and BRTBR like '%").append(brt_sForm.getBrtbr())
					.append("%' ");
		}
		if (!StringUtil.isNull(brt_sForm.getBrtbrnam())) {
			sb1.append(" and BRTBRNAM like '%").append(brt_sForm.getBrtbrnam())
					.append("%' ");
		}
		if (!StringUtil.isNull(brt_sForm.getBrtgacbr())) {
			sb1.append(" and BRTGACBR like '%").append(brt_sForm.getBrtgacbr())
					.append("%' ");
		}
		if (!StringUtil.isNull(brt_sForm.getBrtlqdlev())) {
			sb1.append(" and BRTLQDLEV like '%")
					.append(brt_sForm.getBrtlqdlev()).append("%' ");
		}
		if (!StringUtil.isNull(brt_sForm.getBrtlqdbr())) {
			sb1.append(" and BRTLQDBR like '%").append(brt_sForm.getBrtlqdbr())
					.append("%' ");
		}
		if (!StringUtil.isNull(brt_sForm.getBrtlacseq())) {
			sb1.append(" and BRTLACSEQ like '%")
					.append(brt_sForm.getBrtlacseq()).append("%' ");
		}
		if (sb1.length() > 0) {
			sb.append(" where ").append(sb1.substring(4));
		}
		map.put("sql", sb.toString());
		map.put("pageNo", brt_sForm.getCurPageNo2Int());
		map.put("pageSize", Constants.DEFAULT_MAX_PAGE_RECORD);
		map.put("maxPage", Constants.DEFAULT_MAX_PAGE);
		List<BRT_SForm> list = this.getSqlSession().selectList(
				"brt_s.queryWithPg", map);
		return list;
	}

	@Override
	public List<BRT_SForm> queryForExport(BRT_SForm brt_sForm) {
		return this.getSqlSession().selectList("brt_s.query", brt_sForm);
	}

}
